﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="查看调拨单.aspx.cs" Inherits="syc.Store.查看调拨单" %>

<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>  
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"  UpdateMode="Conditional">
    <ContentTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand=""
 InsertCommand="insert into 废料到发记录(MID,单据号,废料ID,单位ID,日期,数量,单价,备注,保管员,结算方式)
 values(@MID,@单据号,@废料ID,@单位ID,@日期,@数量,@单价,@备注,'',@结算方式);"
    
UpdateCommand="update 废料到发记录 set 废料ID=@废料ID,单位ID=@单位ID,日期=@日期,数量=@数量,单价=@单价,备注=@备注,结算方式=@结算方式
where ID=@ID"
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
    >
<SelectParameters>
<asp:Parameter Name="ID" DbType="Int32" Size="4" DefaultValue="0" />
<asp:Parameter Name="废料ID" DbType="Int32" Size="4" Direction="Output" />
<asp:Parameter Name="单位ID" DbType="Int32" Size="4" Direction="Output" />
<asp:Parameter Name="数量" DbType="Double" Size="9" Direction="Output" />
<asp:Parameter Name="单价" DbType="Double" Size="13" Direction="Output" />
<asp:Parameter Name="日期" DbType="Date" Size="3" Direction="Output" />
<asp:Parameter Name="备注" DbType="String"  Size="100" Direction="Output" />
<asp:Parameter Name="废料名称" DbType="String"  Size="40" Direction="Output" />
<asp:Parameter Name="规格" DbType="String"  Size="40" Direction="Output" />
<asp:Parameter Name="单位" DbType="String"  Size="20" Direction="Output" />

<asp:Parameter Name="单位名称" DbType="String" Size="40" Direction="Output" />
<asp:Parameter Name="记录数" DbType="Int32" Size="4" Direction="Output" DefaultValue="0" />
<asp:Parameter Name="单据号" DbType="Int32" Size="4" Direction="Output"/>
</SelectParameters>

<InsertParameters>
<asp:Parameter Name="MID" Size="4" DbType="Int32"/>
<asp:Parameter Name="单据号" Size="9" DbType="String"/>
<asp:Parameter Name="废料ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="单位ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="日期" DbType="Date"  Size="3"/>
<asp:Parameter Name="数量" Size="9" DbType="Decimal"/>
<asp:Parameter Name="单价" DbType="Decimal" Size="9"/>
<asp:Parameter Name="备注" DbType="String"  Size="40"/>
<asp:Parameter Name="保管员" DbType="String" Size="20" />
<asp:Parameter Name="结算方式" DbType="String" Size="10" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="废料ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="单位ID" Size="4" DbType="Int32"/>
<asp:Parameter Name="日期" DbType="Date"  Size="3"/>
<asp:Parameter Name="数量" Size="9" DbType="Decimal"/>
<asp:Parameter Name="单价" DbType="Decimal" Size="9"/>
<asp:Parameter Name="备注" DbType="String"  Size="40"/>
<asp:Parameter Name="结算方式" DbType="String" Size="10" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Size="4" DbType="Int32"/>
</DeleteParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
    SelectCommand="SELECT [ID], [名称] FROM [废料收货单位]"></asp:SqlDataSource>


<% if(Request.QueryString["id"]!=null) { %>
<div id="wintop" class="wintop" style="display:none;">废料调拨单</div>
<%}else{%>
<div id="wintop" class="wintop" style="display:none;">废料调拨单</div>
<%} %>
<asp:HiddenField ID="Cell_FID" runat="server" Value="" />
<asp:HiddenField ID="Cell_DWID" runat="server" Value="" />
<asp:HiddenField ID="Cell_PM" runat="server" Value="" />
<asp:HiddenField ID="Cell_XH" runat="server" Value="" />
<asp:HiddenField ID="Cell_DW" runat="server" Value="" />
<asp:HiddenField ID="Cell_SL" runat="server" Value="" />
<asp:HiddenField ID="Cell_DJ" runat="server" Value="" />
<asp:HiddenField ID="Cell_BZ" runat="server" Value="" />
<asp:Label ID="BillID" runat="server" Text="0" Visible="False"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
           ></asp:SqlDataSource> 
<asp:Panel ID="Panel1" runat="server" CssClass="panel">
    <asp:Button ID="Button_Save" runat="server" Text="保 存" UseSubmitBehavior="false"
            CssClass="button" onclick="Button_Save_Click"  OnClientClick="checkInput()" />
    <input type="button" value="计算金额" class="button" onclick="calc();" />
    <asp:Button ID="Button_Close" runat="server" Text="关 闭" UseSubmitBehavior="false"  Visible="true"
            CssClass="button" OnClientClick="parent.swin2_close();return false;" />
</asp:Panel>

<asp:Panel ID="Panel2" runat="server" CssClass="panel">
日期：<asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="105px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
 <span style="margin-left:15px;"></span>收货单位：<asp:DropDownList ID="ShouHuoDanWei" runat="server" 
        DataSourceID="SqlDataSource2" DataTextField="名称" DataValueField="ID" 
        Width="121px">
    </asp:DropDownList>
<span style="margin-left:15px;"></span>结算方式：<asp:DropDownList ID="JieSuan" 
        runat="server"  Width="70px">
         <asp:ListItem Value="银行">银行</asp:ListItem>
         <asp:ListItem Value="现金">现金</asp:ListItem>
       
    </asp:DropDownList>
<span style="margin-left:15px;"></span> 单号：<asp:TextBox ID="DanHao" runat="server" CssClass="textbox" Width="60px" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"></asp:TextBox>
<br />备注：<asp:TextBox ID="BeiZhu" runat="server" CssClass="textbox" Width="430px"></asp:TextBox>
</asp:Panel>
<asp:Panel ID="Msg" runat="server" CssClass="panel2">
        <asp:Label ID="Message" runat="server" Text="·准备就绪" CssClass="prompt"></asp:Label>      
 </asp:Panel>
</ContentTemplate>
   </asp:UpdatePanel>   
<asp:Panel ID="Panel3" runat="server">

<script>    putBillHead();</script>
<table border="0" cellpadding="0" 
        style="border-collapse: collapse;font-size:14px; width: 611px; height: 101px;">
<tr>
<td colspan="4" style="font-size:24px;height:36px;" align="center" class=nb>陕西延长石油材料有限公司<br />
    废料调拨单</td>
</tr>
<tr>
<td colspan="2" height="24" class=nb>编码：SYC/ZJ-WL-01</td>
<td colspan="2"class=nb  align="right" style="color:red;padding-right:10px;">No.<span id="DanHaoText" >0000000</span>
</td>
</tr>
<tr>
<td height="24" class=nb >收货单位：<asp:Label ID="Label_ShouHuo" runat="server" Text=""></asp:Label></td>
<td  class=nb align="center">结算方式:<span id="JieSuanText"></span></td>
<td  class=nb align="center">发运方式:汽运&nbsp;&nbsp;&nbsp;</td>
<td class=nb colspan="1"  align="right"><span id="DateText"></span></td>
</tr>
</table>
<style>
tr{height:16pt;}



div{word-break:break-all;}
</style>
<table id="mt" border="1" style="width: 611px;font-size:15;" >
  <tr>
    
    <td rowspan="2" align="center">材料名称</td>
    <td rowspan="2" align="center">规格材质</td>
    <td rowspan="2" align="center">单位</td>
    <td rowspan="2" align="center">数量</td>
    <td colspan="2"align="center">调拨金额</td>
  </tr>
  <tr>
    <td align="center">单价(元)</td>
    <td align="center">金额(元)</td>
  </tr>
  
  <%     
    for(int i=0;i<4;i++) {%>
  <tr>
   
    <td class="nm" tabindex="0" onfocus="dodisplay(this);" style="width: 117px" align="center">&nbsp;</td>
    <td class="nm" style="width: 111px" align="center">&nbsp;</td>
    <td class="nm" style="width: 58px" align="center">&nbsp;</td>
    <td class="nm" align="center"><div tabindex=0 contentEditable style="width:100%;" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"></div></td>
    <td class="nm" align="center"><div tabindex=0 contentEditable style="width:100%;" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"></div></td>
    <td class="nm" style="width: 94px" align="center"></td>
  </tr>
  <%} %>
  <tr>
    <td align="center" class="style1">备注</td>
    <td colspan="5" class="style1"  style="text-align:left;"><div id="BeiZhuText" runat="server"></div></td>   
  </tr>
</table>
<script>    putBillFoot();</script>
<asp:DropDownList runat="server" ID="pmlist" DataSourceID="SqlDataSource3" 
            DataTextField="废料名称" DataValueField="ID" Width="90pt"></asp:DropDownList>
  
<asp:DropDownList ID="RowList" runat="server" DataSourceID="SqlDataSource1" 
            DataTextField="val" DataValueField="txt" ></asp:DropDownList>
</asp:Panel>



</form>

<script >
    var IDList = new Array();
    var ghlist = document.getElementById("pmlist");
    var RowList = document.getElementById("RowList");
    var ShouHuoDanWei = document.getElementById("ShouHuoDanWei");
    var JieSuan = document.getElementById("JieSuan");  
    ShouHuoDanWei.onchange = function() {
    document.getElementById("Label_ShouHuo").innerHTML = ShouHuoDanWei.options[ShouHuoDanWei.selectedIndex].text;
};
document.getElementById("ShouHuoDanWei").onchange();

JieSuan.onchange = function() {
document.getElementById("JieSuanText").innerHTML = JieSuan.options[JieSuan.selectedIndex].text;
};
document.getElementById("JieSuan").onchange();

document.getElementById("Date1").onchange = function() {
    document.getElementById("DateText").innerHTML = this.value;
};
document.getElementById("Date1").onchange();
document.getElementById("DanHao").onchange = function() {
    document.getElementById("DanHaoText").innerHTML = "0000000".substr(this.value.length) + this.value;
};
document.getElementById("DanHao").onchange();
document.getElementById("BeiZhu").onchange = function() {
    document.getElementById("BeiZhuText").innerHTML = this.value;
};
document.getElementById("BeiZhu").onchange();
document.getElementById("Panel1").style.display = "none";
document.getElementById("Panel2").style.display = "none";
document.getElementById("Message").style.display = "none";
    var tar;
    ghlist.style.display = "none";
    ghlist.style.position = "absolute";
    RowList.style.display = "none";

    ghlist.onchange = function() {
        tar.innerHTML = ghlist.options[ghlist.selectedIndex].text;

        var txt = ghlist.options[ghlist.selectedIndex].value.split("*", 4);   
        if (txt == 0) {
            IDList[tar.parentElement.rowIndex - 2] = "";
            tar.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML = "";

        } else {
            tar.nextSibling.innerHTML = txt[2];
            tar.nextSibling.nextSibling.innerHTML = txt[1];
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = txt[3];
        }
    };
    ghlist.onblur = function() {
        ghlist.style.display = "none";
        IDList[tar.parentElement.rowIndex - 2] = "";
        tar.innerHTML = ghlist.options[ghlist.selectedIndex].text;      
        var txt = ghlist.options[ghlist.selectedIndex].value.split("*", 4);
        if (txt == 0) {
            tar.innerHTML = "";
            tar.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = "";
            tar.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML = "";
        } else {
            IDList[tar.parentElement.rowIndex - 2] = txt[0];   
            tar.nextSibling.innerHTML = txt[2];
            tar.nextSibling.nextSibling.innerHTML = txt[1];
            tar.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.innerHTML = txt[3];
        }
    };

    function dodisplay(o) {
        tar = o;
        ghlist.style.left = (getObjectLeft(o) - 2) + "px";
        ghlist.style.top = (getObjectTop(o) - 1) + "px";
        ghlist.style.display = "block";
        ghlist.selectedIndex = 0;
        ghlist.focus();


    }
    //计算金额
    function calc() {  
        var mt = document.getElementById("mt");
        var rows = 0;
        var n, p;
        var total;
//        alert(mt.rows.length);
        for (var i = 2; i < mt.rows.length - 1; i++) {
        row = mt.rows[i];      
        n = Number(row.cells[3].innerText || row.cells[3].textContent);
       
            if (n == NaN) {
                n = -1;
            }

            p = Number(row.cells[4].innerText || row.cells[4].textContent);
            if (p == NaN) {
                p = -1;
            }
            if (n > 0 && p > 0) {              
                row.cells[5].innerHTML = (p * 1000) / 1000 * (n * 1000) / 1000;              
            }
            else {
                row.cells[5].innerHTML = "";
            }
        }
     
       // mt.rows[mt.rows.length - 1].cells[6].innerHTML = total;
    }
    //输入检测
    function checkInput() {
        calc();
        var txt;
        var Cell_FID = document.getElementById("Cell_FID");
        var Cell_DWID = document.getElementById("Cell_DWID");
        var Cell_PM = document.getElementById("Cell_PM");
        var Cell_XH = document.getElementById("Cell_XH");
        var Cell_DW = document.getElementById("Cell_DW");
        var Cell_SL = document.getElementById("Cell_SL");
        var Cell_DJ = document.getElementById("Cell_DJ");


        Cell_FID.value = "";
        Cell_DWID.value = "";
        Cell_PM.value = "";
        Cell_XH.value = "";
        Cell_DW.value = "";
        Cell_SL.value = "";
        Cell_DJ.value = "";
        
        var n, p;
       
        for (var i = 2; i < mt.rows.length - 1; i++) {
            if (IDList[i - 2] > 0) {
                
                Cell_FID.value += "|" + IDList[i - 2];
            
                txt = mt.rows[i].cells[0].innerText;
                if (txt == null) txt = mt.rows[i].cells[1].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_PM.value += "|=*" + txt;
               
                txt = mt.rows[i].cells[1].innerText;
                if (txt == null) txt = mt.rows[i].cells[2].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_XH.value += "|=*" + txt;


                txt = mt.rows[i].cells[2].innerText;
                if (txt == null) txt = mt.rows[i].cells[3].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_DW.value += "|=*" + txt;


                txt = mt.rows[i].cells[3].innerText;
               
                if (txt == null) txt = mt.rows[i].cells[4].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                if (txt == "") continue;
                Cell_SL.value += "|" + txt;
             
         
                txt = mt.rows[i].cells[4].innerText;
                if (txt == null) txt = mt.rows[i].cells[5].textContent;
                txt = txt.replace(/^\s+/, '').replace(/\s+$/, '');
                Cell_DJ.value += "|" + txt;          
            }
        }    
    }
    for (var i = 0; i < RowList.options.length; i++) {

        var s = RowList.options[i].text
        var list = s.split("|=*");

        IDList[i] = list[0];
        mt.rows[i + 2].cells[0].innerText = list[1];
        mt.rows[i + 2].cells[1].innerText = list[2];
        mt.rows[i + 2].cells[2].innerText = list[3];
        mt.rows[i + 2].cells[3].innerHTML = "<div tabindex=0 contentEditable class=a style=width:50pt;onKeyPress='if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false'>" + list[4] + "</div>";
        mt.rows[i + 2].cells[4].innerHTML = "<div tabindex=0 contentEditable class=a style=width:60pt;onKeyPress='if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false'>" + list[5] + "</div>";
        document.getElementById("DateText").innerHTML = list[7];


        document.getElementById("Label_ShouHuo").innerHTML = list[8];
        calc();
    }

    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "pageturn" || textboxs[i].className == "intxt1" || textboxs[i].className == "textbox") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }
    }

  
    var baocun = document.getElementById("Button_Save");

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.tagName != "DIV") return;
        if (event.keyCode == 13) {
            calc();
            e.keyCode = 9
        }
    }
  
   
    document.getElementById("BeiZhu").onchange = function() {
        document.getElementById("BeiZhuText").innerHTML = this.value;
    };

    document.getElementById("BeiZhu").onchange();

   
    
</script>
</body>
</html>
